package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.admin.util.UploadUtil;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyCatalogQueryObject qo, Model model) {
        qo.setOrderBy("sequence");
        model.addAttribute("strategies",strategyService.list());
        model.addAttribute("result",catalogService.query(qo));
        return "strategyCatalog/list";
    }

    @RequestMapping("/saveOrUpdate")@ResponseBody
    public Object saveOrUpdate(StrategyCatalog catalog){

        JSONResult json = new JSONResult();
        try {

            catalogService.saveOrUpdate(catalog);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

    @ResponseBody@RequestMapping("/selectCatalogByStrategyId")
    public Object selectCatalogByStrategyId(Long strategyId){
        return catalogService.selectCatalogByStrategyId(strategyId);
    }
}
